import java.util.Scanner;

class Base {
    public int a;
    public int b;
    public int c=1;

    protected int val;  //protected修饰的变量可以在同一个包同一个类访问，也可以在同一个包中不同的类访问，还可以在不同的包中的子类进行访问

    public Base() {

    }
    public Base(int a, int b, int c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }
    A a1=new A();   //父类和子类的静态块优先执行，然后父类先执行实例块和构造方法，在执行子类的实例块和构造方法
    static{
        System.out.println("Base的静态代码块");
    }

    public void func2() {
        b=90;
        System.out.println(this.b);
    }
}
class A {
    public A() {
        System.out.println("A");
    }
}

class Derived extends Base {
    public int c=2;

    public Derived() {
        this(10,20,30);
    }
    public Derived(int a,int b,int c) {
        super(a,b,c);//显示的调用父类的构造方法，帮助父类的成员进行初始化,必须要放在第一行，之后可以继续通过this初始化自己的成员变量
    }

    A a2=new A();  //实例块

    static{
        System.out.println("Derived的静态代码块");
    }
    public void fun1() {
        System.out.println("haha");
    }
    public void func2() {   //子类中与父类同名的成员变量和方法，优先访问子类的，如果实在想要访问父类的，可以使用super关键字进行访问
        fun1();
        super.func2();
        System.out.println(c);
        System.out.println(a);
    }
    public void func3() {
        super.func2();
        a=30;
        System.out.println(a);
    }

    public void func4() {
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
    }
}

public class JavaInheritance {
    public static void swap(Derived derived1,Derived derived2) {
        int tmp=derived1.val;
        derived1.val=derived2.val;
        derived2.val=tmp;
    }
    public static void main(String[] args) {
        Derived derived1=new Derived();
        Derived derived2=new Derived();
        derived1.val=10;
        derived2.val=20;
        swap(derived1,derived2);
        System.out.println(derived1.val);
        System.out.println(derived2.val);
        //derived1.func2();
        //derived1.func4();
    }
}

//exercise
//1.有父类Base1和子类Sub，在子类中实现一个成员方法计算x，y，z三者的乘积
class Base1 {
    private int x;
    private int y;
    public Base1(int x, int y) {
        this.x = x;
        this.y = y;
    }
    public int getX() {
        return x;
    }
    public int getY() {
        return y;
    }
    public void func() {
        x=20;
    }

}
class Sub extends Base1{
     private int z;
    public Sub(int x, int y) {
        super(x, y);
    }
    public void calculate() {
        Scanner scan=new Scanner(System.in);
        int z=scan.nextInt();
        System.out.println(getX()*getY()*z);
    }

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int x=scan.nextInt();
        int y=scan.nextInt();
        Sub sub=new Sub(x,y);
        sub.calculate();
    }
}
